<?php
// 数据库连接配置
$host = 'localhost';
$dbname = 'itops_help1_center';
$username = 'itops_help1_center';
$password = 'itops_help1_center';

// 初始化数据库连接
try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    die("数据库连接失败：" . $e->getMessage());
}

// 接口响应函数
function success($data = [], $msg = '操作成功') {
    echo json_encode([
        'status' => 'success',
        'data' => $data,
        'msg' => $msg
    ]);
    exit;
}

function error($msg) {
    echo json_encode([
        'status' => 'error',
        'msg' => $msg
    ]);
    exit;
}

// 验证管理员登录状态
function checkLogin() {
    session_start();
    if (!isset($_SESSION['is_admin']) || $_SESSION['is_admin'] != 1) {
        error('请先登录管理员账号');
    }
}